package gui;

import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;

import deck.Suit;
import deck.Value;


public class CardImages {
	private static List<Image> hearts, clubs, spades, diamonds;
	private static Image blue, red;
	
	static{
		hearts = readSuit("resources\\classic-cards\\h\\");
		clubs = readSuit("resources\\classic-cards\\c\\");
		spades = readSuit("resources\\classic-cards\\s\\");
		diamonds = readSuit("resources\\classic-cards\\d\\");
		try {
			blue = ImageIO.read(new File("resources\\classic-cards\\backVert1.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			red = ImageIO.read(new File("resources\\classic-cards\\backVert2.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private static ArrayList<Image> readSuit(String path){
		ArrayList<Image> ret = new ArrayList<Image>();
		for(int i = 0; i < 13; i++){
			Image card = null;
			try {
				card = ImageIO.read(
						new File(path + (i + 1) + ".png"));
			} catch (IOException e) {
				e.printStackTrace();
			}
			ret.add(card);
		}
		return ret;
	}
	
	public static Image getImage(Suit suit, Value value){
		if(suit == null || suit == Suit.RED){
			return red;
		}else if(suit == Suit.BLUE){
			return blue;
		}else{
			int val = 0;
			switch (value){
			case ACE:
				val = 1;
				break;
			case TWO:
				val = 2;
				break;
			case THREE:
				val = 3;
				break;
			case FOUR:
				val = 4;
				break;
			case FIVE:
				val = 5;
				break;
			case SIX:
				val = 6;
				break;
			case SEVEN:
				val = 7;
				break;
			case EIGHT:
				val = 8;
				break;
			case NINE:
				val = 9;
				break;
			case TEN:
				val = 10;
				break;
			case JACK:
				val = 11;
				break;
			case QUEEN:
				val = 12;
				break;
			case KING:
				val = 13;
				break;
			}
			val -= 1;
			switch (suit){
			case DIAMONDS:
				return diamonds.get(val);
			case CLUBS:
				return clubs.get(val);
			case HEARTS:
				return hearts.get(val);
			case SPADES:
				return spades.get(val);
			default:
				return red;
			}
		}
	}
}
